<template>
	<view>
		<view class="container">
		<view class="attentionItem flex flexBei" v-for="(item, index) in attentionList" :key="index">
			<view class="attentionItem_content flex" @click.prevent="navtoUserInfo(item.user_id)">
				<image :src="item.hesd_portrait" ></image>
				<view class="attentionItem_info">
					<view class="attentionItem_title textHd">
						{{item.name}}
					</view>
					<view class="attentionItem_instoduction textHd">
						{{item.user_motto}}
					</view>
				</view>
			</view>
			<button @click.stop="showModel(item.user_id)">取消关注</button>
		</view>
		</view>
		<!-- 内容为空 -->
		<u-empty mode="list" text="暂无粉丝" margin-top="240" v-show="(this.attentionList.length == 0)"></u-empty>
		<!-- 语句提示 -->
		<u-toast ref="uToast"></u-toast>
		<!-- 弹出层 -->
		<u-modal v-model="show"  show-cancel-button @confirm="cancleAttention">
			<view class="slot-content" style="font-size: 28rpx;padding: 0 24rpx;line-height: 72rpx;">
				你将会取消关注这位用户，是否继续?
			</view>
		</u-modal>
	</view>
</template>

<script>
	import { getlike, deletefollow } from '../../api/follow_like.js'
	export default {
		data() {
			return {
				total: '',
				id: '',
				show: false,
				params: {
				  mineId: '',
				  pageNum: 1,
				  pageSize: 5
				},
				attentionList: [],
			}
		},
		onLoad() {
		  this.params.mineId = this.$store.state.userinfo.userId
		  uni.setNavigationBarTitle({
		  	title: '关注'
		  })	
		},
		onReachBottom() {
			if (this.total >= (this.params.pageNum *this.params.pageSize)) {
				 this.getMore()
			} else {
				this.$refs.uToast.show({
					position: 'top',
					title: '没有更多数据了'
				})
			}
		},
		mounted() {
			this.getAttentionList()
		},
		methods: {
		  // 获取关注列表
		  async getAttentionList () {
			const res = await getlike(this.params)
			this.attentionList = res.data.data.data
			this.total = res.data.data.total
		  },
		  // 下拉加载下一页数据
		  async getMoreList () {
			  this.params.pageNum ++
			  const params = this.params
			  const res = await getlike(this.params)
			  this.attentionList = [...this.attentionList, ...res.data.data.data] 
		  },
	      // 取消关注
		  async cancleAttention () {
			  const params = {
				  mineId: this.$store.state.userinfo.userId,
				  followId: this.id
			  }
			  const res = await deletefollow(params)
			  this.getAttentionList()
			  this.$store.dispatch('getUserInfo')
		  },
		  // 弹出层
		  showModel (id) {
		  	this.show = true
		  	this.id = id
		  },
		  // 跳转到用户详情
		  navtoUserInfo (id) {
			  uni.navigateTo({
			  	url: `../user_details/user_details?id=${id}`
			  })
		  }
		}
	}
</script>

<style lang="scss" scoped>
/* 盒子 */
.container {
	margin-top: 30rpx;
}
/* 关注列表 */
button {
	padding: 0 6rpx;
	background-color: #fa3534;
	border-color: #fa3534;
	color: #fff;
	font-size: 24rpx;
}
</style>
